home *** CD-ROM | disk | FTP | other *** search
/ The Best of Select: Games Special 4 / THE BEST OF SELECT Games Special 4 (Select CD-ROM)(1996).iso / win95 / gchess / eval.c < prev    next >
C/C++ Source or Header  |  1995-02-22  |  35KB  |  1,341 lines

  1. /*
  2.   C source for GNU CHESS
  3.  
  4.   Revision: 1990-09-30
  5.  
  6.   Modified by Daryl Baker for use in MS WINDOWS environment
  7.  
  8.   Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  9.   Copyright (c) 1988, 1989, 1990  John Stanback
  10.  
  11.   This file is part of CHESS.
  12.  
  13.   CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  14.   WARRANTY.  No author or distributor accepts responsibility to anyone for
  15.   the consequences of using it or for whether it serves any particular
  16.   purpose or works at all, unless he says so in writing.  Refer to the CHESS
  17.   General Public License for full details.
  18.  
  19.   Everyone is granted permission to copy, modify and redistribute CHESS, but
  20.   only under the conditions described in the CHESS General Public License.
  21.   A copy of this license is supposed to have been given to you along with
  22.   CHESS so you can know your rights and responsibilities.  It should be in a
  23.   file named COPYING.  Among other things, the copyright notice and this
  24.   notice must be preserved on all copies.
  25. */
  26.  
  27. #define NOATOM 
  28. #define NOCLIPBOARD
  29. #define NOCREATESTRUCT
  30. #define NOFONT
  31. #define NOREGION
  32. #define NOSOUND
  33. #define NOWH
  34. #define NOWINOFFSETS
  35. #define NOCOMM
  36. #define NOKANJI
  37.  
  38. #include <windows.h>
  39. #include <stdio.h>
  40.  
  41. #include "gnuchess.h"
  42. #include "defs.h"
  43.  
  44. #ifdef WIN32
  45. #define _BASEETC
  46. #else
  47. #define _BASEETC _based(_segname("_CODE")) 
  48. #endif
  49.  
  50. /*#define taxicab(a,b) taxidata[a][b]*/
  51. #define taxicab(a,b) *(taxidata+a*64+b)
  52.  
  53. #define wking PieceList[white][0]
  54. #define bking PieceList[black][0]
  55. #define EnemyKing PieceList[c2][0]
  56.  
  57. /*extern short distdata[64][64], taxidata[64][64];*/
  58. extern short far *distdata, far *taxidata;
  59.  
  60. /*extern unsigned char nextpos[8][64][64];*/
  61. /*extern unsigned char nextdir[8][64][64];*/
  62. extern unsigned char far * nextpos;
  63. extern unsigned char far * nextdir;
  64.  
  65.  
  66. extern short PieceList[2][16], PawnCnt[2][8];
  67. extern short Pscore[maxdepth], Tscore[maxdepth];
  68. extern short mtl[2], pmtl[2], emtl[2], hung[2];
  69. extern short c1, c2, *atk1, *atk2, *PC1, *PC2, atak[2][64];
  70. extern short ChkFlag[maxdepth], CptrFlag[maxdepth], PawnThreat[maxdepth];
  71. extern short Pindex[64];
  72. extern short PieceCnt[2];
  73. extern short FROMsquare, TOsquare, Zscore, zwndw;
  74. extern short Mking[2][64], Kfield[2][64];
  75. extern short ATAKD, HUNGP, HUNGX, KCASTLD, KMOVD, XRAY, PINVAL;
  76. extern short RHOPN, RHOPNX, KHOPN, KHOPNX, KSFTY;
  77. extern short HasKnight[2], HasBishop[2], HasRook[2], HasQueen[2];
  78. extern short Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
  79. extern short Mking[2][64], Kfield[2][64];
  80. extern short KNIGHTPOST, KNIGHTSTRONG, BISHOPSTRONG, KATAK;
  81. extern short PEDRNK2B, PWEAKH, PADVNCM, PADVNCI, PAWNSHIELD, PDOUBLED, PBLOK;
  82. extern short stage, stage2, Developed[2];
  83. extern short PawnBonus, BishopBonus, RookBonus;
  84.  
  85.  
  86. static short _BASEETC KingOpening[64] =
  87. {0, 0, -4, -10, -10, -4, 0, 0,
  88.  -4, -4, -8, -12, -12, -8, -4, -4,
  89.  -12, -16, -20, -20, -20, -20, -16, -12,
  90.  -16, -20, -24, -24, -24, -24, -20, -16,
  91.  -16, -20, -24, -24, -24, -24, -20, -16,
  92.  -12, -16, -20, -20, -20, -20, -16, -12,
  93.  -4, -4, -8, -12, -12, -8, -4, -4,
  94.  0, 0, -4, -10, -10, -4, 0, 0};
  95.  
  96. static short _BASEETC KingEnding[64] =
  97. {0, 6, 12, 18, 18, 12, 6, 0,
  98.  6, 12, 18, 24, 24, 18, 12, 6,
  99.  12, 18, 24, 30, 30, 24, 18, 12,
  100.  18, 24, 30, 36, 36, 30, 24, 18,
  101.  18, 24, 30, 36, 36, 30, 24, 18,
  102.  12, 18, 24, 30, 30, 24, 18, 12,
  103.  6, 12, 18, 24, 24, 18, 12, 6,
  104.  0, 6, 12, 18, 18, 12, 6, 0};
  105.  
  106. static short _BASEETC DyingKing[64] =
  107. {0, 8, 16, 24, 24, 16, 8, 0,
  108.  8, 32, 40, 48, 48, 40, 32, 8,
  109.  16, 40, 56, 64, 64, 56, 40, 16,
  110.  24, 48, 64, 72, 72, 64, 48, 24,
  111.  24, 48, 64, 72, 72, 64, 48, 24,
  112.  16, 40, 56, 64, 64, 56, 40, 16,
  113.  8, 32, 40, 48, 48, 40, 32, 8,
  114.  0, 8, 16, 24, 24, 16, 8, 0};
  115.  
  116. static short _BASEETC KBNK[64] =
  117. {99, 90, 80, 70, 60, 50, 40, 40,
  118.  90, 80, 60, 50, 40, 30, 20, 40,
  119.  80, 60, 40, 30, 20, 10, 30, 50,
  120.  70, 50, 30, 10, 0, 20, 40, 60,
  121.  60, 40, 20, 0, 10, 30, 50, 70,
  122.  50, 30, 10, 20, 30, 40, 60, 80,
  123.  40, 20, 30, 40, 50, 60, 80, 90,
  124.  40, 40, 50, 60, 70, 80, 90, 99};
  125.  
  126. static short _BASEETC pknight[64] =
  127. {0, 4, 8, 10, 10, 8, 4, 0,
  128.  4, 8, 16, 20, 20, 16, 8, 4,
  129.  8, 16, 24, 28, 28, 24, 16, 8,
  130.  10, 20, 28, 32, 32, 28, 20, 10,
  131.  10, 20, 28, 32, 32, 28, 20, 10,
  132.  8, 16, 24, 28, 28, 24, 16, 8,
  133.  4, 8, 16, 20, 20, 16, 8, 4,
  134.  0, 4, 8, 10, 10, 8, 4, 0};
  135.  
  136. static short _BASEETC pbishop[64] =
  137. {14, 14, 14, 14, 14, 14, 14, 14,
  138.  14, 22, 18, 18, 18, 18, 22, 14,
  139.  14, 18, 22, 22, 22, 22, 18, 14,
  140.  14, 18, 22, 22, 22, 22, 18, 14,
  141.  14, 18, 22, 22, 22, 22, 18, 14,
  142.  14, 18, 22, 22, 22, 22, 18, 14,
  143.  14, 22, 18, 18, 18, 18, 22, 14,
  144.  14, 14, 14, 14, 14, 14, 14, 14};
  145.  
  146. static short _BASEETC  PawnAdvance[64] =
  147. {0, 0, 0, 0, 0, 0, 0, 0,
  148.  4, 4, 4, 0, 0, 4, 4, 4,
  149.  6, 8, 2, 10, 10, 2, 8, 6,
  150.  6, 8, 12, 16, 16, 12, 8, 6,
  151.  8, 12, 16, 24, 24, 16, 12, 8,
  152.  12, 16, 24, 32, 32, 24, 16, 12,
  153.  12, 16, 24, 32, 32, 24, 16, 12,
  154.  0, 0, 0, 0, 0, 0, 0, 0};
  155.  
  156. static short _BASEETC value[7] =
  157. {0, valueP, valueN, valueB, valueR, valueQ, valueK};
  158.  
  159. static short _BASEETC control[7] =
  160. {0, ctlP, ctlN, ctlB, ctlR, ctlQ, ctlK};
  161.  
  162. static short _BASEETC PassedPawn0[8] =
  163. {0, 60, 80, 120, 200, 360, 600, 800};
  164.  
  165. static short _BASEETC PassedPawn1[8] =
  166. {0, 30, 40, 60, 100, 180, 300, 800};
  167.  
  168. static short _BASEETC PassedPawn2[8] =
  169. {0, 15, 25, 35, 50, 90, 140, 800};
  170.  
  171. static short _BASEETC PassedPawn3[8] =
  172. {0, 5, 10, 15, 20, 30, 140, 800};
  173.  
  174. static short _BASEETC ISOLANI[8] =
  175. {-12, -16, -20, -24, -24, -20, -16, -12};
  176.  
  177. static short _BASEETC BACKWARD[16] =
  178. {-6, -10, -15, -21, -28, -28, -28, -28,
  179.  -28, -28, -28, -28, -28, -28, -28, -28};
  180.  
  181. static short _BASEETC BMBLTY[14] =
  182. {-2, 0, 2, 4, 6, 8, 10, 12, 13, 14, 15, 16, 16, 16};
  183.  
  184. static short _BASEETC RMBLTY[15] =
  185. {0, 2, 4, 6, 8, 10, 11, 12, 13, 14, 14, 14, 14, 14, 14};
  186.  
  187. static short _BASEETC KTHRT[36] =
  188. {0, -8, -20, -36, -52, -68, -80, -80, -80, -80, -80, -80,
  189.  -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80,
  190.  -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80};
  191.  
  192. /*
  193.   ptype is used to separate white and black pawns, like this;
  194.   ptyp = ptype[side][piece]
  195.   piece can be used directly in nextpos/nextdir when generating moves
  196.   for pieces that are not black pawns.
  197. */
  198. static short _BASEETC ptype[2][8] =
  199. {
  200.   no_piece, pawn, knight, bishop, rook, queen, king, no_piece,
  201.   no_piece, bpawn, knight, bishop, rook, queen, king, no_piece};
  202.  
  203. static short _BASEETC direc[8][8] =
  204. {
  205.   0, 0, 0, 0, 0, 0, 0, 0,
  206.   10, 9, 11, 0, 0, 0, 0, 0,
  207.   8, -8, 12, -12, 19, -19, 21, -21,
  208.   9, 11, -9, -11, 0, 0, 0, 0,
  209.   1, 10, -1, -10, 0, 0, 0, 0,
  210.   1, 10, -1, -10, 9, 11, -9, -11,
  211.   1, 10, -1, -10, 9, 11, -9, -11,
  212.   -10, -9, -11, 0, 0, 0, 0, 0};
  213.  
  214. static short _BASEETC max_steps[8] =
  215. {0, 2, 1, 7, 7, 7, 1, 2};
  216.  
  217. static short _BASEETC nunmap[120] =
  218. {
  219.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  220.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  221.   -1, 0, 1, 2, 3, 4, 5, 6, 7, -1,
  222.   -1, 8, 9, 10, 11, 12, 13, 14, 15, -1,
  223.   -1, 16, 17, 18, 19, 20, 21, 22, 23, -1,
  224.   -1, 24, 25, 26, 27, 28, 29, 30, 31, -1,
  225.   -1, 32, 33, 34, 35, 36, 37, 38, 39, -1,
  226.   -1, 40, 41, 42, 43, 44, 45, 46, 47, -1,
  227.   -1, 48, 49, 50, 51, 52, 53, 54, 55, -1,
  228.   -1, 56, 57, 58, 59, 60, 61, 62, 63, -1,
  229.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  230.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  231.  
  232. static short _BASEETC qrook[3] = {0, 56, 0};
  233.  
  234. static short _BASEETC krook[3] = {7, 63, 0};
  235.  
  236. static short _BASEETC kingP[3] = {4, 60, 0};
  237.  
  238. static short _BASEETC rank7[3] = {6, 1, 0};
  239.  
  240. static short _BASEETC sweep[8] =
  241. {false, false, false, true, true, true, false, false};
  242.  
  243.  
  244. /* ............    POSITIONAL EVALUATION ROUTINES    ............ */
  245.  
  246. int
  247. evaluate (short int side,
  248.           short int ply,
  249.           short int alpha,
  250.           short int beta,
  251.           short int INCscore,
  252.           short int *slk,
  253.           short int *InChk)
  254.  
  255. /*
  256.   Compute an estimate of the score by adding the positional score from the
  257.   previous ply to the material difference. If this score falls inside a
  258.   window which is 180 points wider than the alpha-beta window (or within a
  259.   50 point wind